package com.kaifamiao.jdbc.features;

import java.sql.*;

public class SupportResultSetType {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        /*
        String driverClassName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/kaifamiao?serverTimezone=Asia/Chongqing";
        String username = "kfm";
        String password = "kfm";
        */

        String driverClassName = "oracle.jdbc.OracleDriver";
        String url = "jdbc:oracle:thin:@localhost:1521:kaifamiao";
        String username = "kaifamiao";
        String password = "kaifamiao";

        Class.forName( driverClassName );
        Connection conn = DriverManager.getConnection( url, username, password );

        // 获得数据库元数据
        DatabaseMetaData meta = conn.getMetaData();

        System.out.println( "当前驱动所支持的结果集类型:" );
        System.out.println( "forward only: " + meta.supportsResultSetType( ResultSet.TYPE_FORWARD_ONLY ));
        System.out.println( "scroll insensitive: " + meta.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE ));
        System.out.println( "scroll sensitive: " + meta.supportsResultSetType( ResultSet.TYPE_SCROLL_SENSITIVE ));

        System.out.println( "当前驱动是否支持指定类型结果集且支持指定并发特性" );
        System.out.println( meta.supportsResultSetConcurrency( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY ) );
        System.out.println( meta.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY ) );
        System.out.println( meta.supportsResultSetConcurrency( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE ) );
        System.out.println( meta.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ) );
        System.out.println( meta.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY ) );
        System.out.println( meta.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE ) );

        System.out.println( "当前驱动是否支持结果集的指定`可保存性`" );
        System.out.println( meta.supportsResultSetHoldability( ResultSet.CLOSE_CURSORS_AT_COMMIT ) );
        System.out.println( meta.supportsResultSetHoldability( ResultSet.HOLD_CURSORS_OVER_COMMIT ) );

        conn.close();
    }

}
